package com.example.streamsqlpark.enums;

import java.io.Serializable;

/**
 * @author voloiono
 * @date 2024/4/17 9:56
 */
public enum ExecutionMode implements Serializable {
    LOCAL(0, "local"),
    /** remote */
    REMOTE(1, "remote"),
    /** yarn-per-job mode */
    YARN_PER_JOB(2, "yarn-per-job"),
    /** yarn session */
    YARN_SESSION(3, "yarn-session"),
    /** yarn application */
    YARN_APPLICATION(4, "yarn-application"),
    /** kubernetes session */
    KUBERNETES_NATIVE_SESSION(5, "kubernetes-session"),
    /** kubernetes application */
    KUBERNETES_NATIVE_APPLICATION(6, "kubernetes-application");

    private final Integer mode;

    private final String name;

    ExecutionMode(Integer mode, String name) {
        this.mode = mode;
        this.name = name;
    }

    public static ExecutionMode of(Integer value) {
        for (ExecutionMode executionMode : values()) {
            if (executionMode.mode.equals(value)) {
                return executionMode;
            }
        }
        return null;
    }

    public static ExecutionMode of(String name) {
        for (ExecutionMode executionMode : values()) {
            if (executionMode.name.equals(name)) {
                return executionMode;
            }
        }
        return null;
    }

    public int getMode() {
        return mode;
    }

    public String getName() {
        return name;
    }

    public static boolean isRemoteMode(Integer value){
        return isRemoteMode(of(value));
    }

    public static boolean isRemoteMode(ExecutionMode mode){
        return REMOTE.equals(mode);
    }
}
